<html>
<head>
    <title>Web sockets test</title>
    <style type="text/css">
    	.container 
      {
    		font-family: "Courier New";
    		width: 680px;
    		height: 300px;
    		overflow: auto;   
                padding:10px; 
    		border: 1px solid black;
                -moz-border-radius:0.2em; 
                -webkit-border-radius:0.2em; 
                border-radius:0.4em;
			}
    </style>
    <script src="jquery-min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var ws;
        var SocketCreated = false;

        


        function WSonOpen() {
            //Log("ws open", "OK");
	  // ws.send("login:" + document.getElementById("txtName").value);
	ws.send("abc");
        };


        function WSonMessage(event) {
            Log(event.data);            
        };


        function WSonClose() {
            Log("ws close", "ERROR");
        };


        function WSonError() {
            Log("error", "ERROR");
        };


        function Log(Text, MessageType) {
            if (MessageType == "OK") Text = "<span style='color: green;'>" + Text + "</span>";
            if (MessageType == "ERROR") Text = "<span style='color: red;'>" + Text + "</span>";
            document.getElementById("LogContainer").innerHTML = document.getElementById("LogContainer").innerHTML + Text + "<br />";
            var LogContainer = document.getElementById("LogContainer");
            LogContainer.scrollTop = LogContainer.scrollHeight;
        };

	function startConn() {

                Log("Start to connect...");
                try {
                    ws = new WebSocket("ws://127.0.0.1:8889/test");
                    SocketCreated = true;
                } catch (ex) {
                    Log(ex, "ERROR");
                    return;
                }
                ws.onopen = WSonOpen;
                ws.onmessage = WSonMessage;
                ws.onclose = WSonClose;
                ws.onerror = WSonError;
        };

        $(document).ready(function () {
              startConn(); 
		//$.get("http://127.0.0.1:8889/test", function(data){
  		//alert("Data Loaded: " + data);
		//});
	      
        });

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <h1></h1>
        <br />
        <div>
 
        </div>
        <input type="text" id="Connection" /><input type="text" id="txtName" value=""/>
        <button id='ToggleConnection' type="button" onclick='ToggleConnectionClicked();'></button>
        <br />
        <br />
        <div id='LogContainer' class='container'></div>
        <br />
        <div id='SendDataContainer'>
        <input type="text" id="DataToSend" size="88" />
        <button id='SendData' type="button" onclick='SendDataClicked();'>·¢ËÍ</button>
        </div>
        <br />
    </form>
</body>
</html>

